<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/03/07 22:35:30 $)
// $RCSfile: rss_view.php,v $ : $Revision: 1.5 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./includes/functions_xml.php");
$xml = new XML;
$template->loadLanguageSection("news", TEMPLATE_DB);

if ($_SWIFT["settings"]["nw_enablerss"] != 1)
{
	exit;
}

$xml->addParentTag("rss", array("version" => "2.0"));
	$xml->addParentTag("channel");
		$xml->addTag("title", sprintf($_SWIFT["language"]["rsslatestnews"], $_SWIFT["settings"]["general_companyname"]));
		$xml->addTag("link", $_SWIFT["swiftpath"]."index.php?_m=news&_a=view");
		$xml->addTag("description", sprintf($_SWIFT["language"]["rsslatestnewsdesc"], $_SWIFT["settings"]["general_companyname"]));
		$xml->addTag("language", $_SWIFT["adminlanguage"]);
		$xml->addTag("copyright", $_SWIFT["settings"]["general_companyname"]);

		// Process the News Items
		if (!empty($_GET["group"]))
		{
			foreach ($_SWIFT["tgroupcache"] as $key=>$val)
			{
				if ($val["title"] == $_GET["group"])
				{
					$tgroupid = $val["tgroupid"];
					$tgrouptitle = $val["title"];
					break;
				}
			}
		}
		// Set default group if we have no group specified
		if (empty($tgroupid))
		{
			$tgroupid = "1";
			$tgrouptitle = "default";
		}

		$maxrssitems = $_SWIFT["settings"]["nw_maxrss"];
		if (empty($maxrssitems))
		{
			$maxrssitems = 15;
		}

		$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."news` AS news LEFT JOIN `". TABLE_PREFIX ."newsdata` AS newsdata ON (news.newsid = newsdata.newsid) WHERE `tgroupid` = '". intval($tgroupid) ."' ORDER BY news.newsid DESC LIMIT ". intval($maxrssitems) .";");
		while ($dbCore->nextRecord())
		{
			if ($dbCore->Record["newstype"] == SWIFTPRIVATE)
			{
				continue;
			}

			$xml->addParentTag("item");
				$xml->addTag("title", htmlspecialchars($dbCore->Record["subject"]));
				$xml->addTag("link", $_SWIFT["swiftpath"]."index.php?_m=news&_a=viewnews&newsid=". intval($dbCore->Record["newsid"]) ."&group=".urlencode($tgrouptitle));
				$xml->addTag("description", htmlspecialchars($dbCore->Record["description"]));
				$xml->addTag("unixdate", $dbCore->Record["dateline"]);
				$xml->addTag("pubDate", date("r", $dbCore->Record["dateline"]));
			$xml->endParentTag("item");
		}

	$xml->endParentTag("channel");
$xml->endParentTag("rss");


header("Content-Type: text/xml".SWIFT_CRLF);
echo $xml->returnXML();

?>